package chapter01.part6;

import chapter01.part2.CreateStream;

import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;

/**
 * 终止流操作 查看值
 *
 * 有些方法返回 Optional<T> 是一种缺少返回值的表达方式
 * 
 * @author insight 
 * @since 2021/7/19
 */
public class TerminalStream {
    public static void main(String[] args) {
        Supplier<Stream<String>> words = CreateStream.getWordsStream();

        Optional<String> max = words.get().max(String::compareToIgnoreCase);
        System.out.println(max.orElse(""));

        Optional<String> first = words.get().filter(s -> s.startsWith("q")).findFirst();
        Optional<String> any = words.get().filter(s -> s.startsWith("q")).findAny();

        boolean anyMatch = words.get().parallel().anyMatch(s -> s.startsWith("q"));
        boolean allMatch = words.get().parallel().allMatch(s -> s.startsWith("q"));
        boolean noneMatch = words.get().parallel().noneMatch(s -> s.startsWith("q"));
    }
}